package com.jinyi.wwdeng.ui.steps.impl

import com.jinyi.base.mvp.BaseModel
import com.jinyi.base.network.IRequestCallback
import com.jinyi.base.network.NetworkUtils
import com.jinyi.wwdeng.AppConfigs
import com.jinyi.wwdeng.network.ApiService
import com.jinyi.wwdeng.ui.steps.contract.StepListContract
import org.json.JSONObject

/**
 * JinYiTest
 *
 * @Author：wwdeng
 * @CreateTime：2024/4/14 18:42
 * <pre>
 * Model层  接口实现类
</pre> *
 */
class StepListModelImpl(iCallBack: StepListContract.Presenter) : BaseModel<StepListContract.Presenter>(iCallBack), StepListContract.Model {
    /**
     * 获取流程数据
     */
    override fun getStepListData() {
        val data = JSONObject(AppConfigs.getSPString(AppConfigs.SP_KEY.SP_HENECREDIT_PROCESS))
        callBack.setStepListData(data)
    }

    /**
     * 提交流程数据
     */
    override fun onSubmitStepAction(params: JSONObject) {
        val httpUrl = ApiService.getHttpUrl(ApiService.API_URL.API_COMMON_URL)
        NetworkUtils.post(httpUrl,params,object : IRequestCallback {
            //请求成功
            override fun onRequestSuccess(data: JSONObject) {
                callBack.onSubmitStepSuccess(data)
            }
            //请求失败
            override fun onRequestError(data: JSONObject) {
                callBack.onRequestError(data.optString("errorMsg"))
            }
            //请求完成
            override fun onRequestFinish() {
                callBack.onRequestFinish()
            }
        })
    }
}
